#pragma once

#include <QObject>
#include <QTimer>
#include <QMutex>
#include <QThread>
#include <QString>

#include "ComSerialPport.h"


class SerialPortControl  : public QObject
{
	Q_OBJECT

public:
	SerialPortControl(QObject *parent);
	~SerialPortControl();

	void start(const QString& port, DEVICE_CONN_TYPE device_conn_type, int baudRate);
	void reconnect(const QString& com_port, int baudRate);

signals:
	void sig_connection_state(int state);
	void sig_receiveDataFromServer(QString);
	void sig_Reconnect(const QString& comport, int baudRate);
	void sig_AsyncSendmessage(const QString& message);
	void sig_AsyncAndWaitSendmessage(const QString& message, int write_timeout, int read_timeout);

private:
	void stop();


private:
	QThread m_workerThread;
	ComSerialPport* m_serial_worker = NULL;
	bool m_running = false;
};
